package com.tanhua.server.controller;

import com.tanhua.server.service.CommentsService;
import com.tanhua.server.service.RocketMqService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/comments")
public class CommentsController {

    @Autowired
    private CommentsService commentsService;
    @Autowired
    private RocketMqService rocketMqService;


    @GetMapping(name = "查询指定圈子的评论数据")
    public ResponseEntity queryComments(String movementId,@RequestParam(defaultValue = "1") Integer page,
                                        @RequestParam(defaultValue = "10")Integer pagesize){


        return commentsService.queryComments(movementId,page,pagesize);

    }

//    {"movementId":"1wfdffdsdvsd","comment":"你好。。。"}
    @PostMapping(name = "保存评论数据")
    public ResponseEntity saveComments(@RequestBody Map map){
        String movementId = (String) map.get("movementId");
        String comment = (String) map.get("comment");

        rocketMqService.sendMsg(movementId,4);
        return commentsService.saveComments(movementId,comment);

    }

}
